home *** CD-ROM | disk | FTP | other *** search
/ Atari Mega Archive 1 / Atari Mega Archive - Volume 1.iso / mint / lib / mntlib44.zoo / mntlib / isctty.c < prev    next >
C/C++ Source or Header  |  1994-03-01  |  752b  |  33 lines

  1. /* _isctty():  determine if a file descriptor refers to this process's
  2.    controlling tty.
  3. */
  4.  
  5. #include <fcntl.h>
  6. #include <stdio.h>
  7. #include <ioctl.h>
  8. #include <unistd.h>
  9. #include <support.h>
  10. #include <stat.h>
  11. #include <mintbind.h>
  12. #include "lib.h"
  13.  
  14. int
  15. _isctty(fd)
  16.   int fd;
  17. {
  18.   struct stat st, tt;
  19.   extern int __mint;
  20.  
  21.   if (!(isatty(fd)) || !(isatty(-1)))
  22.     return 0;
  23.   if (fd == -1)
  24.     return 1;
  25.   if (__mint >= 9 && !Fcntl (fd, &st, FSTAT) && !Fcntl (-1, &tt, FSTAT)) {
  26.     return (st.st_dev == tt.st_dev && st.st_ino == tt.st_ino);
  27.   }
  28.   /* We know that __mint < 9 (the Fcntl's above don't have the chance
  29.      to fail), use the same algorithm that ttyname() uses in this
  30.      case: it returns "/dev/aux" if fd == -2 */
  31.   return fd != -2;
  32. }
  33.